package nus.iss.ga.ui;

import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.EventObject;
import java.util.Vector;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.event.CellEditorListener;
import javax.swing.table.TableCellEditor;

public class ValueEditor extends AbstractCellEditor implements TableCellEditor, ItemListener {

	private ValueRenderer vr = new ValueRenderer();

    public ValueEditor() {
        //vr.addItemListener(this);
     
    }

    @Override
    public Object getCellEditorValue() {
    	return vr.isSelected();
    }

    @Override
    public Component getTableCellEditorComponent(JTable table,
        Object value, boolean isSelected, int row, int col) {
    	System.out.println("Value Renderer - getTableCellEditorComponent is fired ");
        Value v = (Value) value;
        vr.setSelected(v.selected);
        vr.setText(v.value);
        ((DataFileTableModel)table.getModel()).setValueAt(value,row,col);
        
        return vr;
    }

    @Override
    public void itemStateChanged(ItemEvent e) {
        this.fireEditingStopped();
    }



	@Override
	public void addCellEditorListener(CellEditorListener l) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cancelCellEditing() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isCellEditable(EventObject anEvent) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void removeCellEditorListener(CellEditorListener l) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean shouldSelectCell(EventObject anEvent) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean stopCellEditing() {
		// TODO Auto-generated method stub
		return false;
	}

}